﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using Tools = Microsoft.Office.Tools;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace OutlookTags
{
    [ComVisible(true)]
    public partial class ThisAddIn
    {
        TagsController TagsController{get;set;}
        TagsCommandBar TagsCommandBar { get; set; }
       
        
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            TagsController = new TagsController(this.Application);
            TagsCommandBar = new TagsCommandBar();
            TagsController.AttachView(TagsCommandBar);

            TagsPannel uc = new TagsPannel();
            //uc.SetCategories(Application);
            TagsController.AttachView(uc);

            Tools.CustomTaskPane taskPane = CustomTaskPanes.Add(uc, "Tags");            
            taskPane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionRight;
            taskPane.Visible = true;

            //Outlook.MAPIFolder folder = this.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);

            //this.Application.ActiveExplorer().SelectionChange += new Microsoft.Office.Interop.Outlook.ExplorerEvents_10_SelectionChangeEventHandler(ThisAddIn_SelectionChange);

            //CommandBar bar = this.Application.ActiveExplorer().CommandBars.Add("Tags", Office.MsoBarPosition.msoBarTop, true, true);
        }

        void ThisAddIn_SelectionChange()
        {
            //var selection = this.Application.ActiveExplorer().Selection;
            //foreach (var item in selection)
            //{
            //    Outlook.MailItem mail = item as Outlook.MailItem;
            //    if (mail != null)
            //    {
            //        MessageBox.Show(mail.Categories);
            //    }
            //}
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }
        
        #endregion

        
    }
}
